if(!jsx3.lang.Class.forName("ux.cdb.admin.receiptPkg.pkgWizard.ReceiptChooser")) {
	jsx3.lang.Class.defineClass("ux.cdb.admin.receiptPkg.pkgWizard.ReceiptChooser",
			ux.megatron.gui.WizardPanel,
			null,
			function (block) {
				/**
				 * instance initializer
				 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
				 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
				 */
				block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
					this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
				};

				block.prototype.initialize = function(msg) {
					this.contractId = null;
					this.custName = null;
					this.certId = null;
					this.batchApprovalInfoId = null;
					this.partyName = null;

					this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
					this.wizardDlg = this.getAncestorOfType("ux.cdb.admin.receiptPkg.pkgWizard.Builder");
					this.wizard.lockArray = new Array();
					this.mtxCtrtList = this.get("mtxContactList");
					this.mtxProvCtrtList = this.get("mtxAddRcpPkg");
					this.curPage = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@curPage");
					this.pageSize = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@pageNum");
					this.isCountry = this.wizardDlg.opener.isCountry;
					this.orgId = this.wizardDlg.opener.orgId;
					this.orgName = this.wizardDlg.opener.orgName;
					this.wizard.get("buttonNext").disable();
					var me = this;
					this.mtxCtrtList.subscribe(ux.cdb.admin.gui.Matrix.EVENT_CHECKALL,me,me.isSaved);
					this.mtxProvCtrtList.subscribe(ux.cdb.admin.gui.Matrix.EVENT_CHECKALL,me,me.isSaved);

					this.curPage = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@curPage");
					this.pageSize = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@pageNum");
					this.pagebar = this.get("blkPageWheel");
					this.pagebar.initialize();
					this.pagebar.setCompactMode(true);
					this.pagebar.bindWithMatrix(this, this.loadPagination, this.mtxRcpPkg);

					this.loadTempData();
					//not load data from server automatic
					//this.loadContractsData();
				}

				block.prototype.loadPagination = function(msg) {
					this.curPage = (msg && msg.currentPageNumber) ? msg.currentPageNumber : (this.curPage || 1);
					this.loadContractsData();
				};

				block.prototype.loadTempData = function(){
					if(this.isCountry){
						this.wizardDlg.get("windowBar").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@newPackage"),true);
						this.wizardDlg.get("labelMtxName").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@contractRcpList"),true);
						this.wizardDlg.get("blkContactList").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						this.wizardDlg.get("blkAddRcpPkg").setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
						
						this.wizardDlg.get("blkContractID").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						this.wizardDlg.get("blkContractStdName").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						this.wizardDlg.get("blkContractIdentifyId").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						this.wizardDlg.get("blkProvId").setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
						this.wizardDlg.get("blkProvOrgId").setDisplay(jsx3.gui.Block.DISPLAYNONE,true);

						 
					}else{
						this.wizardDlg.get("windowBar").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@newProvincePackage"),true);
						this.wizardDlg.get("labelMtxName").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@contractCountryRcpList"),true);
						this.wizardDlg.get("blkContactList").setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
						this.wizardDlg.get("blkAddRcpPkg").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						
						this.wizardDlg.get("blkContractID").setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
						this.wizardDlg.get("blkContractStdName").setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
						this.wizardDlg.get("blkContractIdentifyId").setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
						this.wizardDlg.get("blkProvId").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						this.wizardDlg.get("blkProvOrgId").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
					}
					this.wizardDlg.get("btnQuery").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
				}

				block.prototype.onRefreshUI = function(){
					this.loadContractsData();
				}

				block.prototype.onQueryClick = function(){
					if(this.isCountry){
						this.contractId = this.wizardDlg.get("blkContractID").getChildren()[1].getValue();
						this.custName = this.wizardDlg.get("blkContractStdName").getChildren()[1].getValue();
						this.certId = this.wizardDlg.get("blkContractIdentifyId").getChildren()[1].getValue();
					}else{
						this.batchApprovalInfoId = this.wizardDlg.get("blkProvId").getChildren()[1].getValue();
						this.partyName = this.wizardDlg.get("blkProvOrgId").getChildren()[1].getValue();
					}
					this.loadContractsData();
				}

				block.prototype.loadContractsData = function(){
					var me = this;
					if(this.isCountry){
						ux.megatron.util.Dwr.callDwr("RetailStudentLoanContractFeedBackCountryUCC",
							"getStudentPreContractList",[this.contractId,this.custName,this.certId,this.curPage,this.pageSize],
							me,me.callBackGetStudentPreContractList,
							"RetailStudentLoanContractFeedBackCountryUCC");
					}else{
						ux.megatron.util.Dwr.callDwr("RetailStudentLoanContractFeedBackProvinceUCC", 
							"getCountryBatchInfoList", [this.batchApprovalInfoId,this.partyName,this.curPage,this.pageSize],
							me,me.getCountryBatchInfoListCallBack, 
							"RetailStudentLoanContractFeedBackProvinceUCC");
					}
				}

				block.prototype.callBackGetStudentPreContractList = function(dwrObjectList){
					if(!dwrObjectList)
						jsx3.log("call callBackContracts failed......"); 
						
					console.log('callBackGetStudentPreContractList data:\n',dwrObjectList);
					this.totalRecordCount = dwrObjectList.content.page.count;
					this.totalPages = (this.totalRecordCount % this.pageSize > 0) ? (parseInt(this.totalRecordCount / this.pageSize) + 1) : (this.totalRecordCount / this.pageSize);
					if (this.totalPages == 0) this.totalPages = 1;
					this.pagebar.setValue(this.curPage,this.totalPages,this.pageSize,this.totalRecordCount);

					var cdfDoc = ux.megatron.util.Dwr.toCdfDocument(dwrObjectList.content.data,"jsxroot",{"sysBorrowContractId":"jsxid"});
					this.mtxCtrtList.setSourceXML(cdfDoc);
					this.mtxCtrtList.repaintData();
				}

				block.prototype.getCountryBatchInfoListCallBack = function(dwrObjectList){
					if(!dwrObjectList)
						jsx3.log("call getCountryBatchInfoListCallBack failed......"); 

					console.log('getCountryBatchInfoListCallBack data:\n',dwrObjectList);
					this.totalRecordCount = dwrObjectList.content.page.count;
					this.totalPages = (this.totalRecordCount % this.pageSize > 0) ? (parseInt(this.totalRecordCount / this.pageSize) + 1) : (this.totalRecordCount / this.pageSize);
					if (this.totalPages == 0) this.totalPages = 1;
					this.pagebar.setValue(this.curPage,this.totalPages,this.pageSize,this.totalRecordCount);

					var cdfDoc = ux.megatron.util.Dwr.toShallowCdf(dwrObjectList.content.data); 
					this.mtxProvCtrtList.setSourceXML(cdfDoc);
					this.mtxProvCtrtList.repaintData();
				}

				block.prototype.isSaved = function(){
					if(this.isCountry){
						if(this.mtxCtrtList.getCheckedNodes().size() == 0){
							this.wizard.get("buttonNext").disable();
						}else{
							this.wizard.get("buttonNext").enable();
						}
					}else{
						if(this.mtxProvCtrtList.getCheckedNodes().size() == 0){
							this.wizard.get("buttonNext").disable();
						}else{
							this.wizard.get("buttonNext").enable();
						}
					}
				}

				block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					var me = this;
					var contarctList = null;
					this.wizard.lockArray = new Array();
					if(this.isCountry){
						contractList = this.mtxCtrtList.getCheckedNodes();
						for(var i = 0;i < contractList.size();i++){
							this.wizard.lockArray.push(contractList.get(i).getAttribute("appBasicInfoId"));
						}
						ux.megatron.util.Dwr.callDwr("RetailStudentLoanContractFeedBackCountryUCC", 
							"tryLockContracts", [this.wizard.lockArray],
							me,me.callBackTryLockContracts, 
							"RetailStudentLoanContractFeedBackCountryUCC");	
					}else{
						contractList = this.mtxProvCtrtList.getCheckedNodes();
						for(var i = 0;i < contractList.size();i++){
							this.wizard.lockArray.push(contractList.get(i).getAttribute("batchApprovalInfoId"));
						}
						ux.megatron.util.Dwr.callDwr("RetailStudentLoanContractFeedBackProvinceUCC", 
							"tryLockBatches", [this.wizard.lockArray],
							me,me.callBackTryLockContracts, 
							"RetailStudentLoanContractFeedBackProvinceUCC");	
					}
					return "NONE";
				}

				block.prototype.callBackTryLockContracts = function(dwrObjectList) {
					if(!dwrObjectList){
						jsx3.log("call getInternalOrgInfo failed......");
					}
					if(dwrObjectList.res.flag == 0 || dwrObjectList.res.flag == 2){
						alert(dwrObjectList.res.msg);
						this.loadContractsData();
						return;
					}
					var batchInfoObj = {};
					this.wizard.ctrtIdsArray = new Array();
					var contarctList = null;
					if(this.isCountry){
						contractList = this.mtxCtrtList.getCheckedNodes();
						batchInfoObj.coorperOrgId = this.orgId;
						batchInfoObj.coorperOrgName = this.orgName;
						batchInfoObj.appStudentCount = contractList.size();
						batchInfoObj.appTotalAmt = 0;
						batchInfoObj.appPeriod = 0;
						batchInfoObj.projectStatusCode = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@pkgWaitAppStatus");

						for(var i = 0;i < contractList.size();i++){
							if(contractList.get(i).getAttribute("appAmt") != null && contractList.get(i).getAttribute("appAmt") != "" && contractList.get(i).getAttribute("appAmt") != undefined){								
								batchInfoObj.appTotalAmt += parseFloat(contractList.get(i).getAttribute("appAmt"));
							}
							//get the max period
							if(contractList.get(i).getAttribute("appPeriod") > batchInfoObj.appPeriod){
								batchInfoObj.appPeriod = contractList.get(i).getAttribute("appPeriod");
							}
							var recordObj = new Object();
							recordObj.appBasicInfoId = contractList.get(i).getAttribute("appBasicInfoId");
							recordObj.virtualApproveObjectId = contractList.get(i).getAttribute("virtualApproveObjectId");
							this.wizard.ctrtIdsArray.push(recordObj);
						}
					}else{
						contractList = this.mtxProvCtrtList.getCheckedNodes();
						batchInfoObj.appStudentCount = 0;
						batchInfoObj.projectStatusCode = ux.megatron.Main.getServer().getDynamicProperty("@cdb@package@pkgWaitAppStatus");
						batchInfoObj.appTotalAmt = 0;//appTotalAmt
						batchInfoObj.coorperOrgId = this.orgId
						batchInfoObj.coorperOrgName = this.orgName;
						batchInfoObj.appPeriod = 0;//null

						for(var i = 0;i < contractList.size();i++){
							if(contractList.get(i).getAttribute("appTotalAmt")){
								batchInfoObj.appTotalAmt += parseFloat(contractList.get(i).getAttribute("appTotalAmt"));
							}
							if(contractList.get(i).getAttribute("appStudentCount")){
								batchInfoObj.appStudentCount += parseFloat(contractList.get(i).getAttribute("appStudentCount"));
							}
							//get the max period
							if(contractList.get(i).getAttribute("appPeriod") > batchInfoObj.appPeriod){
								batchInfoObj.appPeriod = contractList.get(i).getAttribute("appPeriod");
							}
							var recordObj = new Object();
							recordObj.batchApproveInfoId = contractList.get(i).getAttribute("batchApprovalInfoId");
							recordObj.virtualApproveObjectId = contractList.get(i).getAttribute("virtualApproveObjectId");
							this.wizard.ctrtIdsArray.push(recordObj);
						}
					}
					this.wizard.batchInfoCdf = jsx3.xml.CDF.Document.newDocument();
					this.wizard.batchInfoCdf.insertRecord(batchInfoObj, "jsxroot");
					this.wizard.batchInfoObj = batchInfoObj;
					this.wizardDlg.get("btnClose").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
					this.wizard.doNext();
					var packageInfoObj = this.wizard.getDescendantOfName("wizPanel_2");
					if(packageInfoObj){
						packageInfoObj.initialize();
					}
					return null; // return "NONE" to not next panels
				}

				block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not last status
				}

				block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					this.getAncestorOfType("ux.cdb.admin.receiptPkg.pkgWizard.Builder").doClose();
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
					if(!this.getChild(0)) {
						var me = this;
						ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/receiptPkg/pkgWizard/step1/ui/receiptChooserContent.xml", me, me.initialize);
					}
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
					return null; // return "NONE" to not advance panels
				}
			}
	);
}
